package com.lingchen.service.impl;

import com.lingchen.dao.ChoiceDao;
import com.lingchen.entity.Choice;
import com.lingchen.service.ChoiceService;
import com.lingchen.utils.IdGen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author    lingchen
 * Email     838878458@qq.com
 * Time      2018/2/26
 * Function  题库完成类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ChoiceServiceImpl implements ChoiceService {
    @Autowired
    private ChoiceDao choiceDao;

    public int insertChoice(Choice... choices) {
        try {
            for (Choice c : choices) {
                c.setId(IdGen.uuid());
            }
            return choiceDao.insertChoice(choices);
        }catch (Exception e){
            return 0;
        }
    }

    public List<Choice> selectChoice(String courseId, int count) {
        return choiceDao.selectChoice(courseId, count);
    }
}
